package com.qf.smsplatform.search.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.smsplatform.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Author: LeeRui
 * 2021/2/2 下午 10:07
 *
 **/
@RestController
public class SearchController {

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private SearchService searchService;

    //webmaster通过feign组件调用当前接口实现短信数量查询
    @RequestMapping(value = "/search/searchcount", method = RequestMethod.POST)
    Long searchLogCount(@RequestParam("params") String params) throws IOException {
        //将params手动反序列化为Map集合
        Map map = objectMapper.readValue(params, Map.class);

        //调用service查询短信总条数
        Long count = searchService.findLogCount(map);

        //返回
        return count;
    }

    //webmaster通过feign组件调用当前接口实现短信查询显示
    @RequestMapping(value = "/search/search", method = RequestMethod.POST)
    List<Map> searchLog(@RequestParam("params") String params) throws IOException {

        //将params手动反序列化为Map集合
        Map map = objectMapper.readValue(params, Map.class);

        //调用service查询短信并显示
        List<Map> data = searchService.findLogInfo(map);

        //返回
        return data;
    }

    //按短信发送状态统计短信数据配合前端以饼状图显示
    @RequestMapping(value = "/search/statStatus", method = RequestMethod.POST)
    public Map<String, Long> statSendStatus(@RequestParam("params") String params) throws IOException {
        //将params手动的反序列化为Map对象
        Map map = objectMapper.readValue(params, Map.class);

        //调用service查询数据总条数
        Map<String, Long> data = searchService.statistics(map);

        //返回
        return data;
    }
}
